﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using TransFormer.BLL;
using TransFormer.Web.admin.WebModel;

namespace TransFormer.Web.admin.AdminAshx
{
    /// <summary>
    /// ClientList 的摘要说明
    /// </summary>
    public class ClientList : IHttpHandler, IRequiresSessionState
    {
        private BLL.Clients _bll = new Clients();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            int pageIndex = 1;
            int pageSize = 10;

            int.TryParse(context.Request["rows"], out pageSize);
            int.TryParse(context.Request["page"], out pageIndex);

            var dataset = _bll.GetListByPage(string.Empty, string.Empty, (pageIndex - 1) * pageSize + 1, pageIndex * pageSize);
            var list = _bll.DataTableToList(dataset.Tables[0]);
            var data = new EzuiModel<Model.Clients> { rows = list.ToArray(), total = _bll.GetRecordCount(string.Empty).ToString() };
            var jz = new JavaScriptSerializer();
            var jsonData = jz.Serialize(data);
            context.Response.Write(jsonData);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}